/**
 * Created by yudongyang on 2016/3/31 17:30.
 * mail: yudongyang@kehaoinfo.com
 **/

package com.wujie.activies.controller;

import com.wujie.activies.controller.exchangeBean.JSONData;
import com.wujie.activies.model.ActivityType;
import com.wujie.activies.service.IActivityTypeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by yudongyang on 2016/3/31.
 * 活动类型controller
 */
@RestController
@RequestMapping("/attp")
public class ActivityTypeController {
    private static Logger TRACE = LoggerFactory.getLogger(ActivityTypeController.class);
    @Resource
    private IActivityTypeService activityTypeService;

    @RequestMapping(value = "/{id}",method= RequestMethod.GET)
    public String getActivityType(@PathVariable String id){
        JSONData jsonData = new JSONData();
        if(id.equals("all")){
            jsonData.setData(activityTypeService.getAll());
        }else{
            ActivityType at = new ActivityType();
            at.setId(Integer.valueOf(id));
            jsonData.setData(activityTypeService.getAll());
        }
        return jsonData.toString();
    }

    @RequestMapping(value = "/{id}",method= RequestMethod.DELETE)
    public String delActivityType(@PathVariable String id){
        JSONData jsonData = new JSONData();
        activityTypeService.deleteByPrimaryKey(Integer.valueOf(id));
        return jsonData.toString();
    }



    @RequestMapping(value = "/{id}",method= RequestMethod.PUT)
    public String putActivityType(@RequestBody ActivityType activityType,@PathVariable int id){
        JSONData jsonData = new JSONData();
        activityType.setId(id);
        activityTypeService.updateByPrimaryKey(activityType);
        return jsonData.toString();
    }
    @RequestMapping(value = "/add",method= RequestMethod.POST)
    public String postActivityType(@RequestBody ActivityType activityType){
        JSONData jsonData = new JSONData();
        int id = activityTypeService.insertSelective(activityType);
        jsonData.setData(id);
        return jsonData.toString();
    }
}
